import request from '@/request'
/**
 * 下了列表混入
 * @type {{data(): *, methods: {upCallback(*): void, downCallback(): void, loadList(*): void}}}
 */

const RollListMixin = {
	data() {
		return {
			loadMoreStatus: "loadmore",
			pageNum: 0,
			rollList:[],
			query:{}
		}
	},
	// 上拉操作
	onReachBottom() {
		this.upCallback()
	},
	methods: {
		/*上拉加载的回调:  */
		async upCallback() {
		
			if(this.loadMoreStatus == "nomore") return
			this.pageNum++;
			this.loadMoreStatus = "loading";
			const { data } = await request.get(this.APIURL,{
				params:{
					pageNum:this.pageNum,
					pageSize:this.pageSize,
					...this.query
				}
			})
			
			console.log(data.record)
			
			const total = data.total;
			this.loadMoreStatus = "loadmore";
			
			// 最后一页 设置为nomore
			if (this.pageNum == Math.ceil(total/this.pageSize) || total === 0) {
				this.loadMoreStatus = "nomore";
			}
			this.rollList.push(...data.record)
		},
		
		/* 刷新的回调函数 */
		async downCallback() {
			this.loadMoreStatus = "loadmore"
			this.pageNum = 0
			this.rollList = []
			this.upCallback();
		}
	}
	
}

export default RollListMixin;
